package com.atguigu.transform;

import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 回复值有几种结果 数据就被分几组
 * @author wky
 * @create 2021-07-13-18:48
 */
public class Transform_KeyBy {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment senv = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<String> streamSource = senv.readTextFile("src/input/word.txt");
        streamSource.keyBy(new KeySelector<String, String>() {
            @Override
            public String getKey(String s) throws Exception {
               // return s.split(" ")[0]; //按切割的首个单词分组
//                return  s.contains("a")? "含a":"不含a";
                return  s.contains("a")+"";
            }
        }).print();
        senv.execute();
    }
}
